﻿/******************************************************************************
* File description: CameraDisplay.qml
* Function: 摄像头模块
* Current Version: 1.0.0
* Author: JNN
* Date: 2025-07-01
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.0
import QtMultimedia 5.12
import CCustomClass 1.0
import "../components"

Rectangle {
    id: root
    color: "#CFCFCF"

    property string cameraName: "CameraPurify";
    property string cameraId: "-1"            // 如果CameraId非空，则接收Default的值

//    Timer{
//        repeat: true
//        running: root.visible
//        interval: 200
//        onTriggered: {
//        }
//    }

    onVisibleChanged: {
        if(visible){
            CCamera.startCaptureCamera(cameraName)
        }
    }

    Connections{
        target: CCamera
        onSigRefreshCameraImage: {


            if(cameraName != root.cameraName){
                return
            }

            // CameraProvider版
            image.source = ""
            image.source = "image://"+ cameraName +"/" + Math.random()
            // FBO版 ()
            //            fboCamera.update()
        }
    }

    Text{
        color: "white"
        text: "摄像头未连接"
        anchors.centerIn: parent
        font.pixelSize: 10*dp+Math.min(root.width, root.height) * 0.04
        font.bold: true
    }
    CustomImage{
        id:image
        anchors.fill: parent
//        visible: CCamera.isConnected
    }

//    CameraFBOItem{
//        id: fboCamera
//        anchors.fill: parent
////        visible: CCamera.isConnected
//    }


//    Item{

//        anchors.fill: parent
//        visible: root.cameraId !== "-1"
//        Camera {
//            id: camera
//            imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash
//            exposure {
//                exposureCompensation: -1.0
//                exposureMode: Camera.ExposurePortrait
//            }

//            flash.mode: Camera.FlashRedEyeReduction
//            deviceId: root.cameraId

//            imageCapture {
//                onImageCaptured: {
//                    photoPreview.source = preview  // Show the preview in an Image
//                }
//            }
//        }

//        VideoOutput {
//            source: camera
//            anchors.fill: parent
//            focus : visible // to receive focus and capture key events when visible
//        }


//    }

}
